﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ths.Components.SystemModule;
using Ths.Components;

public partial class _framework_setTheme : System.Web.UI.Page
{
    public string CurrentTheme="";
    protected void Page_Load(object sender, EventArgs e)
    {
        CurrentTheme = Ths.Components.SystemModule.SysInstall.GetCurrentTheme();
        if (!IsPostBack)
        {
            Bind();
        }
    }

    public void Bind()
    {
        SysInstall _install = new SysInstall();
        List<ThemeSkin> _list=_install.GetThemeList(true);
        DataList1.DataSource = _list;
        DataList1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string name = "";
        string ControlType = "";
        foreach (DataListItem item in DataList1.Items)
        {
            RadioButton rb=(RadioButton)item.FindControl("RadioButton1");
            TextBox txt = (TextBox)item.FindControl("txt_ControlType");
            if (txt != null)
            {
                ControlType = txt.Text;
            }

            if (rb != null && rb.Checked)
            {

                name=DataList1.DataKeys[item.ItemIndex].ToString();
                break;
            }
            
        }
        Ths.Components.SystemModule.SysInstall.SetCurrentTheme(name,ControlType);
        
        Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "P.cancel();", true);
    }
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
        {

            RadioButton rb = (RadioButton)e.Item.FindControl("RadioButton1");
            if (rb != null)
            {
                if(DataList1.DataKeys[e.Item.ItemIndex].ToString()==CurrentTheme)
                {
                    rb.Checked=true;
                }
            }
        }
    }
}
